package com.zzh.demo.consumer.framework.listener;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * description： <br>
 * createTime: 2018/1/516:17 <br>
 *
 * @author zzh
 */
@WebListener
@Component
@Slf4j
public class SessionListener implements HttpSessionListener {

    public static Map<String, String> testSessionIds = new ConcurrentHashMap<>();

    public static final String TEST_SESSION_ID_KEY = "testSessionId";



    @Override
    public void sessionCreated(HttpSessionEvent httpSessionEvent) {
        log.info("aaaa--created session : " + httpSessionEvent.getSession().getId());
    }


    @Override
    public void sessionDestroyed(HttpSessionEvent httpSessionEvent) {
//        redisService.deleteHash(REDIS_KEY_SESSION, httpSessionEvent.getSession().getAttribute(COOKIE_NAME_JSESSIONID));
        String sessionId = httpSessionEvent.getSession().getId();
        if(testSessionIds.containsKey(sessionId)) {
            String testUser = testSessionIds.get(sessionId);
        }
        log.info("aaaa--destroy session : " + sessionId);
    }
}
